﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BuildCode.Models
{
    public class DataBaseFactory
    {
        public IDataBase GetDataBase(DataBaseEnum dataBase)
        {
            switch (dataBase)
            {
                case DataBaseEnum.PDM:
                    return new PDMReader();
                case DataBaseEnum.Oracle:
                    return new OracleDataBase();
                case DataBaseEnum.SqlServer:
                    return new SqlServerDataBase();
                default:
                    throw new Exception("DataBase Error");
            }
        }
    }

    public class DataBaseCommon
    {
        public string GetProvider(DataBaseEnum dataBase)
        {
            switch (dataBase)
            {
                case DataBaseEnum.Oracle:
                    return "System.Data.OracleClient";
                case DataBaseEnum.SqlServer:
                    return "System.Data.SqlClient";
                default:
                    throw new Exception("DataBase Error");
            }
        }

        public string GetDataType(string provider)
        {
            switch (provider)
            {
                case "System.Data.OracleClient":
                    return "Oracle";
                case "System.Data.SqlClient":
                    return "SqlServer";
                default:
                    throw new Exception("DataBase Error");
            }
        }

        public DataBaseEnum GetBaseEnumByType(string dataType)
        {
            return (DataBaseEnum)Enum.Parse(typeof(DataBaseEnum), dataType);
        }

        public DataBaseEnum GetDataBaseEnum(string provider)
        {
            return (DataBaseEnum)Enum.Parse(typeof(DataBaseEnum), GetDataType(provider));
        }
    }

    public enum DataBaseEnum
    {
        PDM = 0,
        Oracle = 1,
        SqlServer = 2,
    }
}